using System.Windows.Forms;
using pub.CmdUI.Cmd;
using pub.CmdUI.UI.Control;

namespace todo.Cmd.Edit
{
    public class EditCmd : DefaultCmd, ICmdState
    {
        public EditCmd()
        {
            Shortcut = new CmdShortcut(Keys.F2);
        }

        bool ICmdState.Enabled
        {
            get { return TodoApi.Instance.ActiveTodo != null; }
        }

        bool? ICmdState.Checked
        {
            get { return TodoApi.Instance.IsEditing(); }
        }

        public override void Execute(IControlUI controlUi)
        {
            if (TodoApi.Instance.IsEditing() ?? false)
            {
                TodoApi.Instance.EndEdit();
            }
            else
            {
                TodoApi.Instance.BeginEdit();
            }
        }
    }
}